import { api } from '../boot/axios'
import { AssetRelation, Version } from './type'

function url(s: string) {
  if (s==''){
    return ['/api/assets', ''].join('/')
  }
  return ['/api/assets', s.replace('/', ''), ''].join('/')
}

export async function getAssets (){
  const res = await api({
    url: url('get_asset_relation'),
    method: 'get',
  })
  return res.data as AssetRelation[]
}


export async function getCurAssetRelation (id:number){
  const res = await api({
    url: url('get_cur_asset_relation'),
    method: 'post',
    data:{id}
  })
  return res.data as AssetRelation
}

export async function createAssetRelation (equipment_class:string,lv1:string,lv2:string,lv3:string,lv4:string,lv5:string){
  const res = await api({
    url: url('create_asset_relation'),
    method: 'post',
    data:{
      equipment_class,
      lv1,
      lv2,
      lv3,
      lv4,
      lv5,
    }
  })
  return res.data as AssetRelation
}

export async function editAssetRelation (id:number,equipment_class:string,lv1:string,lv2:string,lv3:string,lv4:string,lv5:string){
  const res = await api({
    url: url('update_asset_relation'),
    method: 'patch',
    data:{
      id,
      equipment_class,
      lv1,
      lv2,
      lv3,
      lv4,
      lv5,
    }
  })
  return res.data as AssetRelation
}


export async function softDeleteAssetRelation(id:number) {
  const res = await api({
    url: url('soft_delete_cur_asset_relation'),
    method: 'delete',
    data:{id}
  })
  return res.data as AssetRelation
}

export async function importAssetLv4Relation(lv4:string) {

  
  const res = await api({
    url: url('import_asset_lv4_relation'),
    method: 'post',
    data:{lv4}
  })
  return res.data as AssetRelation
}

export async function importAssetLv5Relation(lv5: string) {
  const res = await api({
    url: url('import_asset_lv5_relation'),
    method: 'post',
    data:{lv5}
  })
  return res.data as AssetRelation
}

export async function importAssetECRelation(equipment_class: string) {
  const res = await api({
    url: url('import_asset_eq_relation'),
    method: 'post',
    data:{equipment_class}
  })
  return res.data as AssetRelation
}